﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using DotNet.Business;
using DotNet.Common;

public partial class newsList : System.Web.UI.Page
{
    #region 变量
    Tab_NewsBll tab_NewsBll = new Tab_NewsBll();
    Tab_NewClassBll tab_NewClassBll = new Tab_NewClassBll();
    int _currentIndex = 1;
    int _pageSize = 20;
    int _classID = 2;
    public string _className = "";
    #endregion

    #region 页面加载
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request.QueryString["i"]!=null)
            {
                this._currentIndex = Convert.ToInt32(Request.QueryString["i"]);
            }
            if (Request.QueryString["c"]!=null)
            {
                this._classID = Convert.ToInt32(Request.QueryString["c"]);
            }
            //绑定新闻类别
            this.bindNewsClass();
            //绑定新闻
            this.bindNews();
        }
    }
    #endregion

    #region 绑定新闻类别
    /// <summary>
    /// 绑定新闻类别
    /// </summary>
    private void bindNewsClass() 
    {
        Tab_NewClass tab_NewClass = tab_NewClassBll.GetModel(this._classID);
        this._className = tab_NewClass.newClassName;
    }
    #endregion

    #region 绑定新闻
    /// <summary>
    /// 绑定新闻
    /// </summary>
    private void bindNews() 
    {
        this.Rep_News.DataSource = tab_NewsBll.pageForNews(this._currentIndex, this._pageSize, this._classID);
        this.Rep_News.DataBind();
    }
    #endregion

    #region 分页按钮
    /// <summary>
    /// 分页按钮
    /// </summary>
    public void htmlPaging()
    {
        string str = null;
        int count = 0;
        count = tab_NewsBll.getRecordCount(this._classID);
        int pcount = count % this._pageSize == 0 ? count / this._pageSize : count / this._pageSize + 1;
        str = "页次：" + this._currentIndex + "/" + pcount + "  每页" + this._pageSize + " 总收录数据" + count + "条";
        str += HtmlControls.pagIng(this._currentIndex, pcount, "newsList.aspx?i", "pageaa", "pagecurrent");
        Response.Write(str);
    }
    #endregion
}
